using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class Area : MyPage
{
    protected string ct_path;
    protected int ct_id;
    protected string areaName;

    protected void Page_Load(object sender, EventArgs e)
    {
        Regex rxEvent = new Regex(@"/(?<event>[0-9]+).aspx$", RegexOptions.ExplicitCapture);

        string rxURL = @"^(?<s1>(?<s0>[^:/\?#]+):)?(?<a1>//(?<a0>[^/\?#]*))?(?<p0>[^\?#]*)(?<q1>\?(?<q0>[^#]*))?(?<f1>#(?<f0>.*))?";
        Regex reArea = new Regex(rxURL, RegexOptions.ExplicitCapture);

        Match m;

        if ((m = rxEvent.Match(Request.Url.ToString())).Success)
        {
            Server.Execute("~/EventDetails.aspx?id=" + m.Groups["event"].Value);
            Response.End();
            return;
        }

        if ((m = reArea.Match(Request.Url.ToString())).Success)
        {
            ct_path = m.Groups["p0"].Value.Substring(1).Replace(".aspx", "");
        }

        string[] locations = ct_path.Replace("_", " ").Split('/');
        areaName = locations[locations.Length - 1];

        Page.Title = String.Format("Crimeradar.co.uk: {0} Crime Map", areaName);
    }

    protected override void SavePageStateToPersistenceMedium(object viewState)
    {

    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        return null;
    }

    protected string GetAreaName()
    {
        return areaName;
    }

    protected string GetJS()
    {
        return ct_path.Replace("_", "-").Replace("/", "_") + ".js";
    }
}
